#####################################################################################
#
# preferences.pl
#   Read interesting data out of the Chrome Preferences file
#   
# References:
#   Jesse Kornblum (http://jessekornblum.livejournal.com/288105.html)
# 
# Plugin Author: Ryan Benson (ryan@obsidianforensics.com)
#
#####################################################################################

package preferences;
use strict;
use JSON;

my %config = (friendlyName   => "Preferences Parser",
              description    => "Reads Chrome Preferences file",
              artifactType   => "preferences",
              remoteLookups  => 0,
              browser        => "Chrome",
              browserVersion => 19,
              version        => 20130709);

sub getConfig       { return %config; }
sub getFriendlyName { return $config{friendlyName}; }
sub getDescription  { return $config{description};; }
sub getArtifactType { return $config{artifactType}; }
sub getRemoteLookups{ return $config{remoteLookups}; }
sub getVersion      { return $config{version}; }

sub pluginmain{
    my $insert_h = $::datastore->prepare(" INSERT INTO preferences (option,key,value) VALUES (?,?,?) ");
	my $preferences_file = $::source_dir . "/Preferences";
	my $data;
	if (open (my $preferences_json, $preferences_file))
	{
		local $/ = undef;
		my $json = JSON->new;
		$data = $json->decode(<$preferences_json>);
		close($preferences_json);
	}

	# Per Host Zoom Levels; these currently are not cleared with rest of browsing history and may be useful
	foreach my $key (keys %{$data->{'profile'}->{'per_host_zoom_levels'}}){
		$insert_h->execute( "Zoom Levels",$key,$data->{'profile'}->{'per_host_zoom_levels'}->{$key} );	}	

	# Default Save Directory
	$insert_h->execute( "Default Save Directory","Path",$data->{'savefile'}->{'default_directory'} );

	# Default Download Directory
	$insert_h->execute( "Default Download Directory","Path",$data->{'download'}->{'default_directory'} );
	
	# Last Select Directory
	$insert_h->execute( "Last Select Directory","Path",$data->{'selectfile'}->{'last_directory'} );

	# Autofill Enabled?
	$insert_h->execute( "Autofill","Enabled?",$data->{'autofill'}->{'enabled'} );

	# Google Services Username
	$insert_h->execute( "Google Services Username","Username",$data->{'google'}->{'services'}->{'username'} );
	
	# Chrome Sync
	foreach my $key (keys %{$data->{'sync'}}){
		$insert_h->execute( "Chrome Sync",$key,$data->{'sync'}->{$key} );	}	

	# Clearing Chrome Data
	foreach my $key (keys %{$data->{'browser'}->{'clear_data'}}){
		$insert_h->execute( "Clearing Chrome Data",$key,$data->{'browser'}->{'clear_data'}->{$key} );	}	
	$insert_h->execute( "Clearing Chrome Data","clear_lso_data_enabled",$data->{'browser'}->{'clear_lso_data_enabled'} );

    ::printStatus("Preferences file parsed");
}

1;
